// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作
const install = (Vue, vm) => {

	// 参数配置对象
	const config = Vue.prototype.$store.state.vuex_config;

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.http.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {

		//基础服务
		login: (params = {}, configuraion = {}) => vm.$u.http.post(config.adminPath +
			'/mobile/login/loginByPassword', params, configuraion),
		uploadFiles: (configuraion = {}) => vm.$u.http.upload(config.adminPath + '/common/multi-upload4uniapp',
			configuraion),

		//字典服务：
		getDictData: (params = {}) => vm.$u.http.get(config.adminPath + '/system/dict/data/type/' + params
			.dictType),

		//机构用户服务：
		queryOrgList: (params = {}) => vm.$u.http.get(config.adminPath + '/system/dept/list?parentId=0',
			params),
		getOrgById: (deptId = {}) => vm.$u.http.get(config.adminPath + '/system/dept/' + deptId),
		queryOrgUserList: (deptId = {}) => vm.$u.http.get(config.adminPath + '/system/user/list?deptId=' +
			deptId),
		queryUserList: (deptId = {}) => vm.$u.http.get(config.adminPath + '/system/user/list',
				deptId),

		// 待领取样品列表
		queryUnReceiveSampleList: (params = {}) => vm.$u.http.get(config.adminPath +
			'/ic/v1/samplelists/recieve', params),
		// 我的样品列表
		queryMySampleList: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/samplelists/my', params),
		queryDelegate2MySampleList: (params = {}) => vm.$u.http.get(config.adminPath +
			'/ic/v1/samplelists/delegate2my', params),

		isMySampleCheck: (id = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/samples/' + id + '/authcheck'),
		querySampleListByStep: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/samples', params),

		// 样品服务：
		querySampleList: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/samples', params),
		querySampleInfo: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/samples/' + params),
		deleteSample: (id = {}) => vm.$u.http.delete(config.adminPath + '/ic/v1/samples?id=' + id),

		//样品服务
		submitSample: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/samples', params),
		modifySample: (params = {}) => vm.$u.http.put(config.adminPath + '/ic/v1/samples', params),
		approveSample: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/samples/' + params.id +
			'/approve', params),
		forwardSample: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/samples/' + params.id +
			'/forward', params),
		delegateSample: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/samples/' + params.id +
			'/delegate/' + params.consumer),
		rejectSample: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/samples/' + params.id +
			'/reject?reason=' + params.reason),
		delegateConfirmSample: (sid, uid, data) => vm.$u.http.post(config.adminPath + '/ic/v1/samples/' + sid +
			'/delegate/'+uid+'/confirm', data),
		fallbackSample: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/samples/' + params.id +
			'/fallback?reason=' + params.reason),

		// 基础服务：登录登出、身份信息、菜单授权、切换系统、字典数据等
		lang: (params = {}) => vm.$u.http.get('/lang/' + params.lang),
		index: (params = {}) => vm.$u.http.get(config.adminPath + '/mobile/index', params),
		getUserInfo: (params = {}) => vm.$u.http.get(config.adminPath + '/mobile/user/getUserInfo', params),
		sendCode: (params = {}) => vm.$u.http.post(config.adminPath + '/mobile/login/sendCode', params),
		registerUser: (params = {}) => vm.$u.http.post(config.adminPath + '/mobile/user/registerUser', params),
		//首页相关api
		getIndexCardInfo: (params = {}) => vm.$u.http.get(config.adminPath + '/mobile/index/getIndexCardInfo',
			params),
		getM2mOrderFlowList: (params = {}) => vm.$u.http.get(config.adminPath +
			'/mobile/index/getM2mOrderFlowList', params),
		//获取卡可购买套餐包
		getM2mOrderPackageList: (params = {}) => vm.$u.http.get(config.adminPath +
			'/mobile/index/getM2mOrderPackageList', params),

		logout: (params = {}) => vm.$u.http.get(config.adminPath + '/mobile/login/logout', params),
		authInfo: (params = {}) => vm.$u.http.get(config.adminPath + '/authInfo', params),
		menuTree: (params = {}) => vm.$u.http.get(config.adminPath + '/menuTree', params),
		switchSys: (params = {}) => vm.$u.http.get(config.adminPath + '/switch/' + params.sysCode),

		// 账号服务：验证码接口、忘记密码接口、注册账号接口等
		validCode: (params = {}) => vm.$u.http.getText('/validCode', params),
		getFpValidCode: (params = {}) => vm.$u.http.post('/account/getFpValidCode', params),
		savePwdByValidCode: (params = {}) => vm.$u.http.post('/account/savePwdByValidCode', params),
		getRegValidCode: (params = {}) => vm.$u.http.post('/account/getRegValidCode', params),
		saveRegByValidCode: (params = {}) => vm.$u.http.post('/account/saveRegByValidCode', params),

		// APP公共服务
		upgradeCheck: () => vm.$u.http.post('/app/upgrade/check', {
			appCode: config.appCode,
			appVersion: config.appVersion
		}),
		commentSave: (params = {}) => vm.$u.http.post('/app/comment/save', params),

		contract: { //合同
			list: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/contracts',
				params),
			detail: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/contracts/' + params.id,
				params),
			save: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/contracts/' + params.id,
				params),
			history: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/contract/history?id=' + params.id,
				params),
			tasks: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/contracttasks?id=' + params.id,
				params),
			reports: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/contracttasks?id=' + params.id,
				params),
		},
		task: { //任务
			list: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/contracttasks',
				params),
			detail: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/contracttasks/' + params.id,
				params),
			history: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/task/' + params.id +
				'/histories'),
			reject: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/contracttasks/' + params.id +
				'/reject'),
			forward: (params = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/contracttasks/' + params.id +
				'/forward'),
		},
		client: { // 客户
			list: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/client/page',
				params),
			add: (data = {}) => vm.$u.http.post(config.adminPath + '/ic/v1/client',
				data),
			detail: (id) => vm.$u.http.get(config.adminPath + `/ic/v1/client/${id}/details`),
			
		},
		// 个人信息修改
		user: {
			saveUserInfo: (params = {}) => vm.$u.http.post(config.adminPath + '/mobile/user/saveUserInfo',
				params),
			infoSavePwd: (params = {}) => vm.$u.http.put(config.adminPath + '/system/user/profile/updatePwd',
				params),
			infoSavePqa: (params = {}) => vm.$u.http.post(config.adminPath + '/sys/user/infoSavePqa', params),
		},

		// 员工用户查询
		empUser: {
			listData: (params = {}) => vm.$u.http.get(config.adminPath + '/sys/empUser/listData', params),
		},

		// 组织机构查询
		office: {
			treeData: (params = {}) => vm.$u.http.get(config.adminPath + '/sys/office/treeData', params),
		},

		// 增删改查例子
		testData: {
			form: (params = {}) => vm.$u.http.post(config.adminPath + '/test/testData/form', params),
			list: (params = {}) => vm.$u.http.post(config.adminPath + '/test/testData/listData', params),
			save: (params = {}) => vm.$u.http.postJson(config.adminPath + '/test/testData/save', params),
			disable: (params = {}) => vm.$u.http.post(config.adminPath + '/test/testData/disable', params),
			enable: (params = {}) => vm.$u.http.post(config.adminPath + '/test/testData/enable', params),
			delete: (params = {}) => vm.$u.http.post(config.adminPath + '/test/testData/delete', params),
		},
		
		// 设备
		device: {
			list: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/device', params),
			// detail: (params = {}) => vm.$u.http.get(config.adminPath + '/ic/v1/device', params)
		}

	};

}

export default {
	install
}
